<template>
<div class="layerRtb layerRtb-threecolumn layerRtb-right">
    <three-title :title="{name:'人员确认'}" :close="false">
        <span tag="i" class="rig_close fr" @click="$parent.$parent.clickFiveShow()"></span>
    </three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "18">
        <div class="analyItem" v-for="(item, index) in discloseData" :key="index">
            <p class="analyItemTit tx-center">{{item.participantsRole}}</p>
            <div class="analyItemCon">
                <div class='flex'>
                    <div class="clearfix col-md-11">
                        <p class="col-md-6">
                            <span class="cLightGray pr8">人员姓名</span>
                            <span>{{item.participantsName}}</span>
                        </p>
                        <p class="col-md-6">
                            <span class="cLightGray pr8">电话</span>
                            <span>{{item.participantsPhone}}</span>
                        </p>
                        <p class="col-md-12" v-if="item.description !== null">
                            <span class="cLightGray pr8">描述</span>
                            <span>{{item.description}}</span>
                        </p>
                    </div>
                    <el-checkbox v-model="checkID[item.id]"  v-if="item.isJoin === 1" disabled></el-checkbox>
                    <el-checkbox v-model="checkID[item.id]"  v-if="item.isJoin === 0"></el-checkbox>
                </div>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
                <div class="tx-center">
                    <input type="button" class="uiBtn-normal uiBtn-blue" value="确定" @click="submitButton()" v-if="buttonIsShow">
                </div>
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { mapGetters, mapMutations } from 'vuex'
import { getLiveonsiteOrderDetails, choosePerson } from '../../../../Resources/Api/index'
export default {
    props: ['type', 'role'],
    data () {
        return {
            buttonIsShow: false, // 按钮是否显示
            discloseData: null, // 交底数据
            checkID: [] // 复选框数组
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'updatePlate', 'twoToThreeInfo', 'userInfo'])
    },
    created () {
        this.getLiveonsiteOrderDetails()
        this.buttonType()
    },
    methods: {
        // 按钮显示与隐藏
        buttonType () {
            if (this.userInfo.as_diquId === 39) {
                if (this.twoToThreeInfo.status === this.type) {
                    this.buttonIsShow = true
                } else {
                    this.buttonIsShow = false
                }
            } else {
                this.buttonIsShow = false
            }
        },
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        // 获取数据
        getLiveonsiteOrderDetails () {
            let parm = {
                orderNo: this.leftInfo.orderno
            }
            // 根据条件阶段查询订单
            getLiveonsiteOrderDetails(parm).then((result) => {
                if (result.data.StatusCode === 1) {
                    this.discloseData = result.data.Body.LiveonsiteEntity
                    this.discloseData.forEach(item => {
                        if (item.isJoin === 1) {
                            this.checkID[item.id] = true
                        } else {
                            this.checkID[item.id] = false
                        }
                    })
                }
            }).catch((error) => {
                console.log(error)
            })
        },
        // 获取cookie
        getCookie (name) {
            let arr = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
            let reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
            if ((arr = document.cookie.match(reg))) { return unescape(arr[2]) } else { return null }
        },
        // 提交订单
        submitButton () {
            let submitIds = []
            this.checkID.forEach((item, index) => {
                if (item) {
                    submitIds.push(index)
                }
            })
            let parm = {
                ids: submitIds.join(','),
                projectOrderCode: this.$route.query.code,
                createUserNo: this.userInfo.as_cardNo,
                createUserName: this.userInfo.as_fullName
            }
            // 提交人员确认
            choosePerson(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    this.setUpDatePlate()
                    this.$parent.$parent.clickFiveShow()
                }
            }).catch(error => {
                console.log(error)
            })
        }
    },
    watch: {
        leftInfo () {
            this.getLiveonsiteOrderDetails()
        },
        $route () {
            this.getLiveonsiteOrderDetails()
        }
    }
}
</script>
